package com.bianyuanren.web.controller.app;


import com.bianyuanren.common.annotation.Log;
import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;
import com.bianyuanren.common.core.page.TableDataInfo;
import com.bianyuanren.common.enums.BusinessType;
import com.bianyuanren.common.utils.poi.ExcelUtil;
import com.bianyuanren.v4.pojo.advertising.PpAdvertising;
import com.bianyuanren.v4.service.advertising.IPpAdvertisingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 边缘人广告位Controller
 * 
 * @author pengpeng
 * @date 2020-06-04
 */
@Controller
@RequestMapping("/app/advertising")
public class AppAdvertisingController extends BaseController
{
    private String prefix = "app/advertising";

    @Autowired
    private IPpAdvertisingService ppAdvertisingService;

    @RequiresPermissions("system:advertising:view")
    @GetMapping()
    public String advertising()
    {
        return prefix + "/advertising";
    }

    /**
     * 查询边缘人广告位列表
     */
    @RequiresPermissions("system:advertising:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PpAdvertising ppAdvertising)
    {
        startPage();
        List<PpAdvertising> list = ppAdvertisingService.selectPpAdvertisingList(ppAdvertising);
        return getDataTable(list);
    }

    /**
     * 导出边缘人广告位列表
     */
    @RequiresPermissions("system:advertising:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PpAdvertising ppAdvertising)
    {
        List<PpAdvertising> list = ppAdvertisingService.selectPpAdvertisingList(ppAdvertising);
        ExcelUtil<PpAdvertising> util = new ExcelUtil<PpAdvertising>(PpAdvertising.class);
        return util.exportExcel(list, "advertising");
    }

    /**
     * 新增边缘人广告位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存边缘人广告位
     */
    @RequiresPermissions("system:advertising:add")
    @Log(title = "边缘人广告位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PpAdvertising ppAdvertising)
    {
        return toAjax(ppAdvertisingService.insertPpAdvertising(ppAdvertising));
    }

    /**
     * 修改边缘人广告位
     */
    @GetMapping("/edit/{advertisingId}")
    public String edit(@PathVariable("advertisingId") Long advertisingId, ModelMap mmap)
    {
        PpAdvertising ppAdvertising = ppAdvertisingService.selectPpAdvertisingById(advertisingId);
        mmap.put("ppAdvertising", ppAdvertising);
        return prefix + "/edit";
    }

    /**
     * 修改保存边缘人广告位
     */
    @RequiresPermissions("system:advertising:edit")
    @Log(title = "边缘人广告位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PpAdvertising ppAdvertising)
    {
        return toAjax(ppAdvertisingService.updatePpAdvertising(ppAdvertising));
    }

    /**
     * 删除边缘人广告位
     */
    @RequiresPermissions("system:advertising:remove")
    @Log(title = "边缘人广告位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ppAdvertisingService.deletePpAdvertisingByIds(ids));
    }
}
